package com.zlz.open.ugs.exchange;

import com.zlz.open.ugs.core.exchange.Exchange;
import com.zlz.open.ugs.core.module.Module;
import com.zlz.open.ugs.exchange.request.UgsRequest;
import com.zlz.open.ugs.exchange.response.UgsResponse;
import org.springframework.web.server.ServerWebExchange;

import java.util.List;


/**
 * @Author: zhulinzhong
 * @Date: 2024/5/30
 */
public class UgsExchangeWrapper implements Exchange.Wrapper {

    private final ServerWebExchange delegate;

    private final List<Module> modules;

    public UgsExchangeWrapper(ServerWebExchange delegate, List<Module> modules) {
        this.delegate = delegate;
        this.modules = modules;
    }


    public UgsExchange wrapper() {
        UgsRequest.Builder requestBuilder = new UgsRequest.Builder();
        UgsRequest request = requestBuilder.request(delegate.getRequest()).build();

        UgsResponse.Builder responseBuilder = new UgsResponse.Builder();
        UgsResponse response = responseBuilder.response(delegate.getResponse()).build();

        return new UgsExchange(delegate, request, response, modules);
    }
}
